/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/29/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/  
package com.application.systemmanager.commons;  

import org.apache.log4j.Logger;
import org.springframework.scheduling.quartz.CronTriggerBean;

import com.application.systemmanager.entity.SystemConfig;
import com.application.systemmanager.service.SystemManagerService;

/**   
 * TODO 预警定时器初始化
 * @author  Alex   
 * @since  jdk1.6   */
public class InitializingCronTrigger extends CronTriggerBean{
	private static final Logger logger = Logger.getLogger(InitializingCronTrigger.class);
	private SystemManagerService systemManagerService;
	/**
	 * 得到触发条件
	 * 
	 * @param configr
	 * @return
	 */
	public String updateExpression(SystemConfig config)
	{
		String value = config.getConfigValue();
		String cornExpress = "0 0 "+value+" * * ?";
		logger.info("设置预警提示时间：" + cornExpress);
		//取数据库中配置好的开始时间
		return cornExpress;
	}

	public void setSystemManagerService(SystemManagerService systemManagerService) {
		this.systemManagerService = systemManagerService;
		try{
			SystemConfig config = systemManagerService.findSystemConfigByCode("4100101");		
			if(config != null)
			{
				setCronExpression(updateExpression(config));
			}
			else
			{
				setCronExpression("0 0 9 * * ?");
			}
		}catch(Exception ex){
			
		}
	}
}
